package utils

import (
	"github.com/mojocn/base64Captcha" // 注意将base64Captcha 内容全部拷贝到 base64\!captcha@v1.3.6 内
	"image/color"
)

// Captcha 获取验证码
type Captcha struct {
	Id   string
	BS64 string
	Code int
}

var store = base64Captcha.DefaultMemStore

// GetCaptcha 验证码图片转换加密
func GetCaptcha() (id string, base64 string, err error) {

	rgbaColor := color.RGBA{0, 0, 0, 0}

	fonts := []string{"wqy-microhei.ttc"}

	driver := base64Captcha.NewDriverMath(50, 140, 0, 0, &rgbaColor, base64Captcha.DefaultEmbeddedFonts, fonts)

	captcha := base64Captcha.NewCaptcha(driver, store)

	id, base64, _, err = captcha.Generate()
	return id, base64, err
}

// VerityCaptcha 验证码校验
func VerityCaptcha(id string, resultCaptcha string) bool {
	return store.Verify(id, resultCaptcha, true)
}
